﻿using System;
using System.Globalization;
using System.Windows.Data;
namespace CoreModule.Converters
{
    /// <summary>
    /// 线行 转换。
    /// </summary>
    public class LinearMapConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        public float SourceBegin { get; set; } = 0;
        /// <summary>
        /// 
        /// </summary>
        public float SourceEnd { get; set; } = 100;
        /// <summary>
        /// 
        /// </summary>
        public float TargetBegin { get; set; } = 0;
        public float TargetEnd { get; set; } = 100;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var x = MathF.Min(MathF.Max((float)value, SourceBegin), SourceEnd);
            return TargetBegin + (x - SourceBegin) * (TargetEnd - TargetBegin) / (SourceEnd - SourceBegin);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return 0;
        }
    }
}
